package com.senseu.pages;

import com.senseu.base.BasePage;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.openqa.selenium.support.FindBy;

import java.time.Duration;
import java.util.Arrays;

public class SplashPage extends BasePage {

    public SplashPage(AppiumDriver driver) {
        super(driver);
    }

    @FindBy(id = "com.senseu.baby:id/kown")
    private WebElement know;

    public PermissionSettingPage clickKnow() {
        // 滑动到最底部
        final var finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
        var start = new Point(600, 1600);
        var end = new Point (660, 495);
        var swipe = new Sequence(finger, 1);
        swipe.addAction(finger.createPointerMove(Duration.ofMillis(0),
                PointerInput.Origin.viewport(), start.getX(), start.getY()));
        swipe.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
        swipe.addAction(finger.createPointerMove(Duration.ofMillis(1000),
                PointerInput.Origin.viewport(), end.getX(), end.getY()));
        swipe.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
        driver.perform(Arrays.asList(swipe));
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // keep silent
        }
        know.click();
        // TODO: 2025/6/30 jack 判断系统版本
        return new PermissionSettingPage(driver);
    }
}
